local shuomeng = fk.CreateSkill{
    name = "wk_heg__shuomeng",
}

Fk:loadTranslationTable{
  ["wk_heg__shuomeng"] = "说盟",
  [":wk_heg__shuomeng"] = "当你成为其他角色使用红桃牌的目标结算后，你可令其摸一张牌，然后其可交给你两张红色牌， <a href=':DoGiveDeputy'>遣调</a>此武将牌于其至你回合开始。",

  ["#wk_heg__shuomeng-give"] = "说盟：交给 %dest 两张红色手牌",
  ["wk_heg__shuomeng_give"] = "交给牌 遣调孙乾",
  ["wk_heg__shuomeng_slash"] = "视为被使用【杀】",

  ["$wk_heg__shuomeng1"] = "你我唇齿相依，共御外敌，何如？",
  ["$wk_heg__shuomeng2"] = "今兵薄势寡，可遣某为使往说之。",
}

local H = require "packages.ol_hegemony.util"
local HG = require "packages.new_heg_diy_my.util"

shuomeng:addEffect(fk.CardUseFinished,{
    anim_type = "special",
    can_trigger = function(self, event, target, player, data)
       return player:hasSkill(shuomeng.name) and target ~= player and data.card and data.card.suit == Card.Heart
       and data.tos and table.find(data.tos, function(id) return id == player end)
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        if target.dead then return false end
        target:drawCards(1, shuomeng.name)
        if #target:getCardIds("he") >= 2 then
        local cards = room:askToCards(target,{
            min_num = 2,
            max_num = 2,
            include_equip = false,
            skill_name = shuomeng.name,
            pattern = ".|.|heart,diamond|hand|.|.",
            prompt = "#wk_heg__shuomeng-give::"..player.id,
            cancelable = true,
        })
        if #cards == 2 then
        room:obtainCard(player, cards, false, fk.ReasonPrey)
        if (player.general == "wk_heg__sunqian" or player.deputyGeneral == "wk_heg__sunqian") and target:getMark("@wk_give_deputy") == 0 then
          if player.dead or target.dead then return end
          local isDeputy = H.inGeneralSkills(player, shuomeng.name)
          if isDeputy then
            HG.DoGiveDeputy(room, player, target, "wk_heg__sunqian", player.kingdom, isDeputy == "d")
          end
            room:setPlayerMark(player, "wk_give_deputy_sunqian", 1)
          end
        end
      end
    end,
})

shuomeng:addEffect(fk.TurnStart,{
    is_delay_effect = true,
    anim_type = "special",
    can_trigger = function(self, event, target, player, data)
      return target:getMark("wk_give_deputy_sunqian") == 1 and player:getMark("@wk_give_deputy") == "wk_heg__sunqian"
    end,
    on_cost = Util.TrueFunc,
    on_use = function(self, event, target, player, data)
      HG.StopGiveDeputy(player.room, player, shuomeng.name)
      player.room:setPlayerMark(target, "wk_give_deputy_sunqian", 0)
    end,
})

return shuomeng